#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
#include <QKeyEvent>
#include <QMouseEvent>
#include <QEvent>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    //
    timerid = startTimer(1000);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::keyPressEvent(QKeyEvent *ev)
{
    qDebug() << "jin";
    if(ev->key() == Qt::Key_W)
    {
        qDebug("w被按下");
    }
}

//鼠标进入窗口时触发
void Widget::enterEvent(QEvent *event)
{
    qDebug() << "鼠标进入";
}

void Widget::leaveEvent(QEvent *event)
{
    qDebug() << "鼠标退出";
}

void Widget::mousePressEvent(QMouseEvent *ev)
{
    qDebug() << ev->pos();
    if(ev->button() == Qt::LeftButton)
    {
        qDebug() << "左键点击";
    }
    if(ev->button() == Qt::RightButton)
    {
        qDebug() << "右键点击";
    }
}

void Widget::timerEvent(QTimerEvent *event)
{
    int tmp = ui->lcdNumber->intValue();
    if(event->timerId() == timerid)
    {
        qDebug() << timerid;
        if(tmp <= 0)
        {
            killTimer(timerid);
            return;
        }
        ui->lcdNumber->display(--tmp);
    }
}
